<template>
	<view>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text class="cuIcon-titles text-purple"></text>预览
			</view>
		</view>
		<examCard :Obj="item.scores">考试结果</examCard>
		<baseCard :Obj="item.exams">证书</baseCard>
		<pduCard :Obj="item.pdus">积攒PDU</pduCard>
		<view class="padding">
			<button data-id="shareBtn" open-type="share" class="cu-btn block bg-purple margin-tb-sm lg">
				<text class="cuIcon-upload"></text> 分享小程序</button>
		</view>
		<view class="padding-sm">
			<view class="solid-bottom">
			</view>
			<view class="padding text-center">更新于 {{item.crdate}}</view>
		</view>
		<view class="cu-modal" :class="modalName=='Modal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-purple justify-end">
					<view class="content">提示</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					登录已失效，请重新登录~
				</view>
				<view class="padding flex flex-direction">
					<button class="cu-btn bg-purple lg" @tap="hideModal">确定</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import baseCard from './components/baseCard.vue'
	import pduCard from './components/pduCard.vue'
	import examCard from './components/examCard.vue'
	export default {
		components: {
			baseCard,
			pduCard,
			examCard			
		},
		data() {
			return {
				item: {},
				modalName: '',
				platform:this.$platform
			}
		},
		methods: {
			hideModal() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			}
		},		
		onShareAppMessage(res) {
			var openid = uni.getStorageSync('openid');
			return {
				title: 'PMP成绩查询',
				path: `/pages/scores/scores?openid=${openid}&platform=${this.platform}`,
				success: (res) => {
					console.log('转发成功',res);
				},
				fail: (res) => {
					console.log("转发失败", res);
				}
			}
		},
		async onLoad(e) {
			if (!e.openid) {
				this.item = uni.getStorageSync('item')
			} else {
				var [error, res] = await this.$http({
					url: `/wx/scores/${e.openid}`
				});
				if (res && res.data.ret === 0) {
					this.item = res.data.item
				} else {
					this.modalName = 'Modal'
				}
			}
		}
	}
</script>

<style>

</style>
